<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>系统人员</title>
    <script th:src="@{/layui/layui.js}" type="text/javascript"></script>
    <link th:href="@{/layui/css/layui.css}" rel="stylesheet" />
</head>
<body>
<div id="roleAdd" type="text/html" class="layui-container" >
    <form class="layui-form" style="margin: 10px 10px">
        <div class="layui-form-item">
            <label class="layui-form-label">角色名称</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" lay-verify="required|name" name="name" autocomplete="off" placeholder="角色名称，输入中文">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">角色描述</label>
            <div class="layui-input-block">
                <textarea class="layui-textarea" name="content" placeholder="输入描述"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">角色状态</label>
            <div class="layui-input-block">
                <input type="radio" name="status" value="0" title="可用" checked>
                <input type="radio" name="status" value="1" title="不可用">
            </div>
        </div>
        <div class="layui-form-item" style="display: none">
            <div class="layui-input-block">
                <a class="layui-btn" lay-submit="" lay-filter="submitBtnRoleForm" id="submitBtnRoleForm">
                    提交
                </a>
            </div>
        </div>
    </form>
</div>
<script>
    var $;
    layui.use(['form','jquery'],function () {
        var form = layui.form;
        $ = layui.jquery;

        form.verify({
            name:[/^[\u4e00-\u9fa5]{2,}$/,'输入两个或以上中文']
        })

        form.on('submit(submitBtnRoleForm)',function (data) {
            var formData = data.field;
            $.ajax({
                type:'post',
                url:'/system/role/add',
                data:formData,
                dataType:'json',
                success:function (result) {
                    if(result.is){
                        let index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);//关闭父页面窗口
                    }
                }
            })
        })
    })
    function btnSubmit() {
        $("#submitBtnRoleForm").click();
    }
</script>
</body>
</html>